__author__ = 'vivienfanghua'


class Solution(object):
    def longestPalindrome(self, s):
        """
        :type s: str
        :rtype: str
        """
        self.s = s
        self.l = 0
        self.length = 0
        le = len(s)
        if le < 2:
            return s
        for i in range(le - 1):
            self.judge(i, i + 1)
            self.judge(i, i)
        return s[self.l:self.l + self.length]

    def judge(self, j, k):
        while j >= 0 and k < len(self.s):
            if self.s[j] != self.s[k]:
                break
            j -= 1
            k += 1
        if self.s[j+1] == self.s[k-1] and k - j -1 > self.length:
            self.length = k - j - 1
            self.l = j + 1


a = Solution()
print a.longestPalindrome("babad")